//Person类派生了Student类；SchoolCard类是Student类的内嵌类
//请分析：Student类构造函数的调用情况
#include <iostream>
#include <string>
using namespace std;
class SchoolCard
{
public:
    SchoolCard(long scid=-1,double m=0):id(scid),money(m)
    {
        cout<<"SchoolCard CON"<<endl;
    }
    void save(double m)
    {
        money=money+m;
    }
    void consume(double m)
    {
        money=money-m;
    }
    void print() const
    {
        cout<<"SchoolCard id: "<<id<<endl;
        cout<<"SchoolCard  money: "<<money<<endl;
    }
private:
    double money;
    long id;
};

class Person
{
public:
    Person(string n = "", string id = "\0") : name(n), ID(id)
    {
        cout << "Person CON" << endl;
    }
    int getBirthYear() const //出生年份
    {
        if (ID.empty() == 1)
        {
            return -1;
        }
        else
        {
            string year;
            year = ID.substr(6, 4);
            return stoi(year);
        }
    }
    void print() const
    {
        cout << "Name: " << name << endl;
        cout << "ID: " << ID << endl;
    }

protected:
    string name;
    string ID; //身份证号
};

class Student : public Person
{
public:
    Student(string n = "", string id = "", string s = "", string sid = "",long schoolCardID=-1,double money=0) \
    :sCard(schoolCardID,money),Person(n, id),school(s), SID(sid)
    {
        cout << "Student CON" << endl;
    }
    void print() const
    {
        Person::print();
        cout << "School:" << school << endl;
        cout << "SID: " << SID << endl;
        (this->sCard).print();
    }
    int getEntranceYear() const //入学年份
    {
        if (SID.empty() == 1)
        {
            return -1;
        }
        else
        {
            string year;
            year = SID.substr(0, 4);
            return stoi(year);
        }
    }
    SchoolCard& getSchoolCard()
    {
        return sCard;
    }

protected:
    string school;
    string SID; //学号
    SchoolCard sCard;
};
int main()
{
    Student stu1("Tom", "42010119980101456x", "SCUEC", "201915002",8001,45);
    cout << "============================" << endl;
    stu1.Person::print();
    cout << "============================" << endl;
    stu1.print();
    cout << "============================" << endl;
    stu1.getSchoolCard().save(99);
    stu1.print();
    return 0;
}